package com.yu.hu.feature

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.yu.hu.feature.debug.DebugItem
import com.yu.hu.feature.debug.DebugScreen
import com.yu.hu.feature.debug.crash.CrashListScreen
import com.yu.hu.feature.main.MainScreen
import com.yu.hu.feature.navigation.CrashList
import com.yu.hu.feature.navigation.DebugBaseRoute
import com.yu.hu.feature.navigation.DebugRoute
import com.yu.hu.feature.navigation.Main

/**
 * huyu create
 * 2025/11/4 9:12
 */

fun NavGraphBuilder.buildFeatureNavGraph(navController: NavController) {
    composable<Main> {
        MainScreen { navController.navigate(DebugBaseRoute) }
    }
    if (BuildConfig.DEBUG) buildDebugNavGraph(navController)
}

//debug页面
private fun NavGraphBuilder.buildDebugNavGraph(navController: NavController) {
    navigation<DebugBaseRoute>(startDestination = DebugRoute) {
        composable<DebugRoute> {
            DebugScreen(onItemClick = navController::navigateToDebugItem)
        }
        composable<CrashList> { CrashListScreen() }
    }
}

private fun NavController.navigateToDebugItem(item: DebugItem) {
    when (item) {
        DebugItem.CRASH_LIST -> navigate(CrashList)
    }
}